/**********************************************************************/
/*
Author: Karan Makkar
Created: Nov 2023
Description: Course Category Shares and Ratings, 2022 Online Survey
Output: Table A29
*/
/**********************************************************************/


/*----------------------------------------------------*/
* Section: Setup
/*----------------------------------------------------*/

* include filepaths 
if "$master_run" !="1" include "./Do/SET_FILEPATHS.do"

clear all
set more off
set matsize 11000

* Log
cap log close
global prefix: display %tdCYND td(`c(current_date)')
log using "$KP_logs/${prefix}_course_descriptives.txt", text replace

/*----------------------------------------------------*/
* Section: Data Cleaning
/*----------------------------------------------------*/

/***********
Import, Clean
************/

* 2022
u "${KP_deid_survey}/2022/Clean/071323_survey_22_deid_clean.dta", clear

* Keeep only control sample respondents
keep if completed == 1 & consented == 1 & verified == 1 & control_sample ==1

* Standardize Course 1 Rating to 1/6
replace course1_rating = course1_rating/6

*Create, Label Dummies
tabulate course1_cat, gen(course1_cat)

foreach var of varlist course1_cat*{
    replace `var' = `var'*100
}

* Label
label var course1_cat1 "Engineering"
label var course1_cat2 "IT"
label var course1_cat3 "Finance"
label var course1_cat4 "Office Admin"
label var course1_cat5 "Management"
label var course1_cat6 "Lifestyle"
label var course1_cat7 "Agriculture"
label var course1_cat8 "Food \& Beverage"
label var course1_cat9 "Sales \& Marketing"
label var course1_cat10 "Foreign language"
label var course1_cat11 "Sociobehavioral"
label var course1_cat12 "Other"
label var course1_rating "Course Usefulness Rating (1/6 (low)- 1(high))"

*Course Shares
eststo t1: estpost summ course1_cat8 course1_cat9 course1_cat6 course1_cat3 course1_cat2 course1_cat5 course1_cat7 course1_cat12 course1_cat1 course1_cat4 course1_cat11 course1_cat10

* Course Ratings
bysort course1_cat: egen mean_course1_rating = mean(course1_rating) if !mi(course1_cat)
sum mean_course1_rating
local meanrating = round(r(mean), .01)
drop course1_cat
foreach var of varlist course1_cat*{
    replace `var' =. if `var' !=100
    replace `var' = mean_course1_rating if `var' ==100
}

* Mean Course Rating
eststo t2: estpost summ course1_cat8 course1_cat9 course1_cat6 course1_cat3 course1_cat2 course1_cat5 course1_cat7 course1_cat12 course1_cat1 course1_cat4 course1_cat11 course1_cat10

* Make Table
esttab t1 t2 using $KP_output/tables/descriptive/tex/TableA29.tex, ///
cell("mean(fmt(%9.2f))") ///
collabels(none) ///
label ///
nonum ///
nomtitles ///
stats(N, label("Observations") fmt(%9.0f)) ///
title("Course Category Shares and Ratings: 2022 Online Survey") ///
prehead(`"\hline \hline"') ///
prefoot(`"\\ "') ///
posthead(`"Course Category & Percent Selected(\%) & Mean Course Rating (1/6 (low)- 1(high)) \\"' `"& (1) & (2) \\"' `"\hline"') ///
postfoot(`"Mean & & `meanrating' \\"' `"Batches & 18-22 & 18-22 \\"' `"\hline"') ///
replace 
